﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using API_Service.BizLogic.WipLogApi;
using Nancy;
using Newtonsoft.Json;

namespace API_Service.Module
{
    public class SNControlModule : BaseAPIModule
    {

        private SNControlService snService = new SNControlService();

        public SNControlModule() : base("/sncontrol")
        {
            Get["/"] = _ => Response.AsJson("sn control module");

            # region sn control module

            Get["/checksn"] = _ =>
            {
                string sn = (string)Request.Query["sn"];
                string group = (string)Request.Query["group"];

                ExecutionResult<dynamic> result = snService.Check_SN(group, sn);

                return Response.AsJson(result);
            };

            Post["/scandata"] = _ =>
            {
                try
                {
                    string sn = (string)Request.Form["sn"];
                    string group = (string)Request.Form["group"];
                    string line = (string)Request.Form["line"];
                    string emp = (string)Request.Form["emp"];

                    ExecutionResult<dynamic> result = snService.ScanData(sn, group, line, emp);

                    return Response.AsJson(result);
                }
                catch (Exception ex)
                {
                    ExecutionResult<dynamic> result = new ExecutionResult<dynamic>
                    {
                        Message = ex.Message,
                        Status = false
                    };
                    return Response.AsJson(result);
                }
               
            };

            #endregion

        }



    }
}